<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\widgets\Pjax;
use yii\grid\GridView;
use kartik\export\ExportMenu;

/* @var $this yii\web\View */
/* @var $searchModel app\models\MsgSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'OA消息';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="msg-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]);  ?>

    <div class="col-lg-12 col-md-12" style="margin-bottom: 15px;">
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'method' => 'get',
                    'options' => ['class' => 'input-group col-md-12'],
                    'fieldConfig' => [
                        'template' => '<div class="col-lg-12">{input}</div>',
                    ]
                ])
        ?>

        <div class="col-lg-4 col-md-4">
            <label style="float: left;margin-top: 5px;">标题</label>
            <div style="overflow: hidden;">
                <?php
                $datas = app\models\Msg::find()->all();
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->title;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'title',
                    'options' => ['style' => 'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>
            </div>
        </div>


        <div class="col-md-5 col-lg-5">
            <label style="float: left;margin-top: 5px;">发送类型</label>
            <div style="overflow: hidden;">
                <?php
                echo $form->field($searchModel, 'msgtype')->dropDownList(['会议消息' => '会议消息', 'OA办文' => 'OA办文'], ['prompt' => '全部']);
                ?>        
            </div>
        </div>


        <div class="col-md-3 col-lg-3">
            <?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?> 
            <?= Html::a('新建消息', ['create'], ['class' => 'btn btn-primary']) ?> 
        </div>

    </div>

    <div class="col-md-12 text-right" style="margin: 15px 0 15px 15px;">



        <!--隐藏打印和导出功能-->
        <!--        <button class="btn btn-default glyphicon glyphicon-print" onclick="printme()"> 打印</button>
                <span>&nbsp;&nbsp;</span>-->
        <?Php
//        echo ExportMenu::widget([
//            'dataProvider' => $dataProvider,
//            'dropdownOptions' => [
//                'label' => '导出Excel',
//                'class' => 'btn btn-default',
//                'icon' => '',
//            ],
//            'showColumnSelector' => false,
//            'exportConfig' => [
//                ExportMenu::FORMAT_TEXT => false,
//                ExportMenu::FORMAT_PDF => false,
//                ExportMenu::FORMAT_CSV => false,
//                ExportMenu::FORMAT_EXCEL_X => false,
//                ExportMenu::FORMAT_HTML => false
//            ],
//            'columns' => [
////                ['class' => 'yii\grid\SerialColumn'],
////            'id',
//                'msgtype',
//                'isforward',
//                'forwardid',
//                'title',
//                'description',
//                'content',
//                'addman',
//                'addmanid',
////             'addtime',
//                'isfinish',
//                'sendtime',
//                'meetingtime_start',
//                'meetingtime_end',
//                'meetingplace',
//            ]
//        ]);
        ?>
    </div>

    <?php ActiveForm::end(); ?>    
    <?php Pjax::begin(); ?>
    <?=
    GridView::widget([
        'id' => 'tableContainer',
        'dataProvider' => $dataProvider,
        'columns' => [
            //     ['class' => 'yii\grid\SerialColumn'],
            //'id',
            [
                'attribute' => 'title',
                'label' => '标题',
                'format' => 'raw',
                'value' => function ($model) {
                    return Html::a($model->title, ['msg/view', 'id' => $model->id]);
                },
                        'contentOptions' => ['style' => ''],
                        'headerOptions' => ['style' => ''],
                    ],
                    'msgtype',
                    //'isforward',
                    //'forwardid',
                    'description',
                    // 'content',
//                    'addman',
                    // 'addmanid',
//             'addtime',
                    // 'isfinish',
                    'sendtime',
                    // 'meetingtime_start',
                    // 'meetingtime_end',
//                    'meetingplace',
                    [
                        'class' => 'yii\grid\ActionColumn',
                        'template' => '{delete}',
                        'buttons' => [
                            //update button
//                    'update' => function ($url) {
//                        return Html::a('<span class="fa fa-search"></span>编辑', $url, [
//                                    'title' => Yii::t('app', 'Update'),
//                                        // 'class' => 'btn btn-primary btn-md',
//                        ]);
//                    },
                            //update button
                            'delete' => function ($url) {
                                return Html::a('<span class="fa fa-search"></span>删除', $url, [
                                            'title' => Yii::t('app', 'Delete'),
                                            'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                                            'data-method' => 'post',
                                            'data-pjax' => '0',
                                                //  'class' => 'btn btn-primary btn-md',
                                ]);
                            },
                                ],
                            ],
                        ],
                    ]);
                    ?>
                    <?php Pjax::end(); ?>
</div>
<script>
    var global_Html = "";
    function printme() {
        global_Html = document.body.innerHTML;
        document.body.innerHTML = $('#tableContainer').html();
        $('.btn').hide();
        $('.pagination').hide();
        $('a').each(function () {
            $(this).replaceWith($(this).html());
        });
        window.print();
        window.setTimeout(function () {
            document.body.innerHTML = global_Html;
        }, 300);
    }

</script>